/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLVIRTUAL_PAGE_INTERFACE_H
#define PLVIRTUAL_PAGE_INTERFACE_H

#include <stddef.h>
using namespace std;

class PLVirtualPageManager;

/**
 * Interface for the paging methodes.
 */
class PLVirtualPageInterface {
public:
	/**
	 * Init the virtual memory management.
	 * This also create the page directory for the kernel and set it as
	 * the curent page directory.
	 *
	 * @param virtualpagemanager The pointer to the virtual page manager.
	 */
	virtual void init(PLVirtualPageManager *virtualpagemanager) = 0;
	/**
	 * Get the physical address of a virtual address.
	 *
	 * @param virtualaddr The virtual address to get the physical address for.
	 * @return The resulting physical address.
	 */
	virtual void *getPhysicalAddress(void *virtualaddr) = 0;
	/**
	 * Map a physical page to a virtual address.
	 *
	 * @param physaddr Physical address.
	 * @param virtualaddr Virtual address to map to.
	 * @param flagsTable Flags for the table.
	 */
	virtual void mapPage(void *physaddr, void *virtualaddr, int flagsTable) = 0;
	/**
	 * Set other flags for the virtual address.
	 *
	 * @param virtualaddr The virtual address to set.
	 * @param flagsTable The new flags to set.
	 */
	virtual void setFlags(void *virtualaddr, int flagsTable) = 0;
	/**
	 * Get the page size for the current virtual memory management.
	 *
	 * @return The page size.
	 */
	virtual int pageSize() = 0;
	/**
	 * Set the current page directory to another page directory.
	 *
	 * @param newCurrentPageDirectory The new current page directory.
	 */
	inline void setCurrentPageDirectory(uint32_t *newCurrentPageDirectory);
protected:
	uint32_t *m_currentPageDirectory;
};

void PLVirtualPageInterface::setCurrentPageDirectory(uint32_t *newCurrentPageDirectory) {
	m_currentPageDirectory = newCurrentPageDirectory;
}

#endif
